import { IPSDEField } from '../defield/ipsdefield';
import { IPSDER1N } from './ipsder1-n';
import { IPSDER1NDEFieldMap } from './ipsder1-ndefield-map';
import { IPSDEDataQuery } from '../ds/ipsdedata-query';
import { IPSSysSFPlugin } from '../../res/ipssys-sfplugin';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDER1NDEFieldMapImpl extends PSModelObjectImpl implements IPSDER1NDEFieldMap {
  get codeName(): string {
    return this.M.codeName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  protected majorpsdefield: IPSDEField | null = null;

  getMajorPSDEField(): IPSDEField | null {
    if (this.majorpsdefield != null) return this.majorpsdefield;
    const value = this.M.getMajorPSDEField;
    if (value == null) {
      return null;
    }
    const ipsder1n = this.getParentPSModelObject('dataentity.der.IPSDER1N') as IPSDER1N;
    if (ipsder1n != null) {
      this.majorpsdefield = ipsder1n.getMajorPSDataEntityMust().findPSDEField(value);
    }
    return this.majorpsdefield;
  }

  get majorPSDEField(): IPSDEField | null {
    return this.getMajorPSDEField();
  }

  getMajorPSDEFieldMust(): IPSDEField {
    const value = this.getMajorPSDEField();
    if (value == null) {
      throw new Error('未指定主实体属性');
    }
    return value;
  }

  get mapType(): 'SUM' | 'AVG' | 'MAX' | 'MIN' | 'COUNT' | 'USER' | 'USER2' | 'USER3' | 'USER4' {
    return this.M.mapType;
  }

  get memo(): string {
    return this.M.memo;
  }

  protected minorpsdedataquery: IPSDEDataQuery | null = null;

  getMinorPSDEDataQuery(): IPSDEDataQuery | null {
    if (this.minorpsdedataquery != null) return this.minorpsdedataquery;
    const value = this.M.getMinorPSDEDataQuery;
    if (value == null) {
      return null;
    }
    const ipsder1n = this.getParentPSModelObject('dataentity.der.IPSDER1N') as IPSDER1N;
    if (ipsder1n != null) {
      this.minorpsdedataquery = ipsder1n.getMinorPSDataEntityMust().findPSDEDataQuery(value);
    }
    return this.minorpsdedataquery;
  }

  get minorPSDEDataQuery(): IPSDEDataQuery | null {
    return this.getMinorPSDEDataQuery();
  }

  getMinorPSDEDataQueryMust(): IPSDEDataQuery {
    const value = this.getMinorPSDEDataQuery();
    if (value == null) {
      throw new Error('未指定从实体数据查询');
    }
    return value;
  }

  protected minorpsdefield: IPSDEField | null = null;

  getMinorPSDEField(): IPSDEField | null {
    if (this.minorpsdefield != null) return this.minorpsdefield;
    const value = this.M.getMinorPSDEField;
    if (value == null) {
      return null;
    }
    const ipsder1n = this.getParentPSModelObject('dataentity.der.IPSDER1N') as IPSDER1N;
    if (ipsder1n != null) {
      this.minorpsdefield = ipsder1n.getMinorPSDataEntityMust().findPSDEField(value);
    }
    return this.minorpsdefield;
  }

  get minorPSDEField(): IPSDEField | null {
    return this.getMinorPSDEField();
  }

  getMinorPSDEFieldMust(): IPSDEField {
    const value = this.getMinorPSDEField();
    if (value == null) {
      throw new Error('未指定从实体属性');
    }
    return value;
  }

  get name(): string {
    return this.M.name;
  }

  protected pssyssfplugin: IPSSysSFPlugin | null = null;

  getPSSysSFPlugin(): IPSSysSFPlugin | null {
    if (this.pssyssfplugin != null) return this.pssyssfplugin;
    const value = this.M.getPSSysSFPlugin;
    if (value == null) {
      return null;
    }
    this.pssyssfplugin = this.getPSModel4('res.IPSSysSFPlugin', value, 'getPSSysSFPlugin') as IPSSysSFPlugin;
    return this.pssyssfplugin;
  }

  get psSysSFPlugin(): IPSSysSFPlugin | null {
    return this.getPSSysSFPlugin();
  }

  getPSSysSFPluginMust(): IPSSysSFPlugin {
    const value = this.getPSSysSFPlugin();
    if (value == null) {
      throw new Error('未指定后台扩展插件');
    }
    return value;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get cls(): string {
    return 'PSDER1NDEFieldMapImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'dataentity.der.IPSDER1NDEFieldMap') return true;
    return super.instanceof(cls);
  }
}
